import torch
import numpy as np
from torch.utils.data import TensorDataset

x = np.random.random((4, 5))  # 创建一个4行5列矩阵，元素值0~1随机
y = np.random.random((4, 1))

print(type(x))  # <class 'numpy.ndarray'>
print(x)
print('================================================')

# 将NumPy数组转换为PyTorch张量
x_tensor = torch.from_numpy(x)
y_tensor = torch.from_numpy(y)

# 创建一个TensorDataset
dataset = TensorDataset(x_tensor, y_tensor)

for i in range(len(dataset)):
    print(dataset[i])






